package org.socialnetwork.service;

import java.util.List;

import org.abac4j.annotations.Rule;
import org.abac4j.context.PostProcessor;
import org.abac4j.domain.AnnotatedEffect;
import org.socialnetwork.dao.PhotoDAO;
import org.socialnetwork.pojo.Photo;
import org.socialnetwork.pojo.Usuario;
import org.socialnetwork.rules.RatingChecker;
import org.socialnetwork.rules.PhotoByDescriptionChecker;

public class PhotoService {
	PhotoDAO dao = new PhotoDAO();
	
	@Rule(condition="#{restrictByRating(arg0, arg1)}", effect=AnnotatedEffect.POST_PROCESS, postProcessor=RatingChecker.class)
	public List<Photo> getUserPictures(Usuario theOtherPerson, Usuario me) {
		return dao.getUserPictures(theOtherPerson.getUserId());
	}
	
	@Rule(condition="#{inWorkingTime(currentTime)}", effect=AnnotatedEffect.ALLOW_EXECUTION, postProcessor=PostProcessor.class)
	public List<Photo> getWorkingTimeAllowedPictures(Usuario theOtherPerson) {
		return dao.getUserPictures(theOtherPerson.getUserId());
	}
	
	@Rule(condition="#{photoByDescription(arg0)}", effect=AnnotatedEffect.POST_PROCESS, postProcessor=PhotoByDescriptionChecker.class)
	public List<Photo> getPicturesByDescription(Usuario theOtherPerson, String regex) {
		return dao.getUserPictures(theOtherPerson.getUserId());
	}
}
